<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../../connection/connection.php';
include "../../value/value_kr.php";
$monitor = $_REQUEST['monitor'];
$monitorname=$_REQUEST['monitorname'];

	$sql = "SELECT cs.szUser,cs.iUser,cc.*,co.name FROM carcrime cc ,caruser cs,configcamera co where cs.iUser=cc.iuser and co.id=cc.cameraID ";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery.js"></script>


 <link rel="stylesheet" href="../../css/jquery-ui.css" />
 <script type="text/javascript" src="../../js/jquery-ui.js"></script>
 <script type="text/javascript" src="../../js/globalize.js"></script>
<style>
.ui-widget-content{
	border:1px solid #4A4A4A;
}	
.ui-spinner-input{
	margin: 0px 20px 0px 4px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	ScrollTable();
	
});
function MyResize(){
	ScrollTable();
}

function ScrollTable(){
	wid = $("table#tablebody2").parent().css('width');
	wid = wid.slice(0,-2)-17;
	$("table#tablebody2").css("width", wid);
	$("table#tablebodyheader").css("width", wid);
	$('table#tablebody2').parent().scrollTop(0);
	OnTRCSS();
}
function OnTRCSS(){
	$("table.tbchung tr:even").each(function(){
		$(this).css("background-color","#eff3fa");
	});
}
</script>
<script type="text/javascript">
    $(function() {
        $( "#datepickerfrom" ).datepicker({
            showOn: "button",
            buttonImage: "../../images/calendar.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd",
            autoSize: true
        });
        $( "#datepickerto" ).datepicker({
            showOn: "button",
            buttonImage: "../../images/calendar.gif",
            buttonImageOnly: true,
            dateFormat: "yy-mm-dd",
            autoSize: true
        });
    });

    $(function() {
   	 var checkexistus = '<?=$_SESSION['iduser']?>';
   	if(checkexistus==''){
   		admin_logout();
   		}
   });
    
    function admin_logout(){
    	window.location="../../view_logout.php?changepage=admin";
    }  

    function onclickSearch(){
    	window.location = "../../search/searchcarnums.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>";
    }
    function onclickView(){
    	window.location = "../../index.php?viewaction=none";
    }
    
</script>
<script type="text/javascript">
function validate(evt)
{
 if(evt.keyCode!=8)
 {
 var theEvent = evt || window.event;
 var key = theEvent.keyCode || theEvent.which;
 key = String.fromCharCode( key );
 var regex = /[0-9]|\./;

 if( !regex.test(key) )
{
   theEvent.returnValue = false;

   if(theEvent.preventDefault) theEvent.preventDefault();

 }
 }
}
function sortAndPagingCarcrime(string,flagDesc){
	var winH =window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
	
	var carnumber = document.getElementById('txtcarnumber').value;
	
	var fromdate = document.getElementById('datepickerfrom').value;
	var hourfrom = document.getElementById('txtHour_from').value;
	var minutefrom = document.getElementById('txtMinutes_from').value;
	var secondfrom = document.getElementById('txtSeconds_from').value;

	var todate = document.getElementById('datepickerto').value;
	var hourto = document.getElementById('txtHour_to').value;
	var minuteto = document.getElementById('txtMinutes_to').value;
	var secondto = document.getElementById('txtSeconds_to').value;

	$.ajax({url:"sortAndPagingCarcrime.php?string="+string+"&flagDesc="+flagDesc+"&carnumber="+carnumber+"&fromdate="+fromdate+"&hourfrom="+hourfrom+"&minutefrom="+minutefrom+"&secondfrom="+secondfrom+"&todate="+todate+"&hourto="+hourto+"&minuteto="+minuteto+"&secondto="+secondto+"&winH="+winH,success:function(result){
		var expr = new RegExp('>[ \t\r\n\v\f]*<', 'g');
		var response_html_fixed = result.replace(expr, '><');
		document.getElementById('idtablecarcrime').innerHTML = response_html_fixed;
		ScrollTable();
		}
	});
	 
}
function searchAll_Carcrime(){
	document.getElementById('txtcarnumber').value = "";
	document.getElementById('datepickerfrom').value = "";
	document.getElementById('datepickerto').value = "";

	var winH =window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
	
	$.ajax({url:"searchAll_Carcrime.php?winH="+winH,success:function(result){
		document.getElementById('idtablecarcrime').innerHTML = result;
		ScrollTable();
		}
	});
}
function loadCarcrime_Mo(){
	var winH =window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
	$.ajax({url:"ajax_load_content-carcrime.php?winH="+winH,success:function(result){
		document.getElementById('idtablecarcrime').innerHTML = result;
		ScrollTable();
		}
	});
}
$.widget( "ui.spinnerhour", $.ui.spinner, {
    options: {
    	 min : 0,
 	    max : 23,
 	    showOn : 'both'
    },
 
    _parse: function( value ) {
      if ( typeof value === "string" ) {
        // already a timestamp
        if ( Number( value ) == value ) {
          return Number( value );
        }
        return  Globalize.parseInt( value );
      }
      return value;
    },
 
    _format: function( value ) {
      return Globalize.format( value, "d2" );
    }
  });

$.widget( "ui.spinnermunite", $.ui.spinner, {
    options: {
    	 min : 0,
 	    max : 59,
 	    showOn : 'both'
    },
    _parse: function( value ) {
      if ( typeof value === "string" ) {
        // already a timestamp
        if ( Number( value ) == value ) {
          return Number( value );
        }
        return  Globalize.parseInt( value );
      }
      return value;
    },
 
    _format: function( value ) {
      return Globalize.format( value, "d2" );
    }
  });

$(function() {
	$("#txtHour_from").spinnerhour();
	$("#txtHour_from").bind("keypress",function(event){
		validateHour(this,event);
	});
	$("#txtHour_to").spinnerhour();
	$("#txtHour_to").bind("keypress",function(event){
		validateHour(this,event);
	});
	
	$("#txtMinutes_from").spinnermunite();
	$("#txtMinutes_from").bind("keypress",function(event){
		validateMunite(this,event);
	});
	$("#txtSeconds_from").spinnermunite();
	$("#txtSeconds_from").bind("keypress",function(event){
		validateMunite(this,event);
	});
	$("#txtMinutes_to").spinnermunite();
	$("#txtMinutes_to").bind("keypress",function(event){
		validateMunite(this,event);
	});
	$("#txtSeconds_to").spinnermunite();
	$("#txtSeconds_to").bind("keypress",function(event){
		validateMunite(this,event);
	});
});

//validate
function validateHour(ele,evt)
{
     if(evt.keyCode!=8)
     {
	     var theEvent = evt || window.event;
	     var key = theEvent.keyCode || theEvent.which;
	     key = String.fromCharCode( key );
	     var regex = /[0-9]/;
		
	     if( !regex.test(key) )
	    {
	       theEvent.returnValue = false;
	
	       if(theEvent.preventDefault) theEvent.preventDefault();
	
	     }else{
	    	 //theEvent.preventDefault();
	    	 OnChangeHour(key,ele);
	    	 theEvent.returnValue = false;
	    	 if(theEvent.preventDefault) theEvent.preventDefault();
	     }
     }
}

function validateMunite(ele,evt)
{
     if(evt.keyCode!=8)
     {
	     var theEvent = evt || window.event;
	     var key = theEvent.keyCode || theEvent.which;
	     key = String.fromCharCode( key );
	     var regex = /[0-9]/;
	     if( !regex.test(key) )
	    {
	       theEvent.returnValue = false;
	
	       if(theEvent.preventDefault) theEvent.preventDefault();
	
	     }else{
	    	 OnChangeMunite(key,ele);
	    	 theEvent.returnValue = false;
	    	 if(theEvent.preventDefault) theEvent.preventDefault();
	     }
     }
}

//onchange from
	 function OnChangeHour(key,ele){
	  	 	var value = $(ele).val();
	  	 	if(value.length>2){
	  	 		if(value.slice(0,1)==0){
	  	 			value = value.slice(1);
	  	 		}
	  	 	}
	  	 if(value.length==0){value = "0"+key;}
  	 else{
  		value = parseInt(value)+key;
  	 }
   	if(value < 00){
   		$(ele).val('23');
   	}else if(value > 23 ){
   		$(ele).val('00');
   	}else{
   		$(ele).val(value);
   	}
}

function OnChangeMunite(key,ele){
	var value = $(ele).val();
	 	if(value.length>2){
	 		if(value.slice(0,1)==0){
	 			value = value.slice(1);
	 		}
	 	}
  	 if(value.length==0){value = "0"+key;}
  	 else{
  		value = parseInt(value)+key;
  	 }
	if(value < 00){
		$(ele).val('59');
	}else if(value > 59 ){
		$(ele).val('00');
	}else{
		$(ele).val(value);
	}
}

function loadpos(){
	var winHf = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$("#divscroll").css("height", parseInt(winHf - 240));
}
</script>
</head>

<?php include 'show_function_popup_carcrime.php';?>
<body onresize="MyResize();" onload="loadpos();loadCarcrime_Mo();load_popup_carCrime();">
<p id="maylya" ><input type="hidden"  id="mayly" name="mayly" /></p>
   <div id="menu" style="text-align: center;">
    	<ul class="amenu">
        	<li><a  onclick="onclickSearch();"><input class="csssearch" type="button"/></a></li>
            <li style="background:#1e7bbd"><a href=""><input class="cssadminchoose" type="button"/></a></li>
            <li style="width: 215px;"><a onclick="onclickView();"><input class="cssview" type="button"/></a>
	            <select class="seltopadmin" disabled="disabled">
	            	<option><?php echo $monitorname;?></option>
	            </select>
            </li>
            <li><a onclick="admin_logout()" style="cursor:pointer" ><input class="csslogout" type="button"/></a></li>
        </ul>
         <div class="clear"></div>
    </div>
    <div id="submenu">
    	<ul class="asubmenu">
        	<li><a href="../content-monitor-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_monitor?></a></li>
            <li><a href="../camera/content-camera-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_camera?></a></li>
           <li><a href="../car-crime-input-by-user/car-crime-input-by-user-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_carcrimeuser?></a></li>
            <li><a href=""  style="background:#034776; border-radius:6px"><?php echo $l_carcrime?></a></li>
            <li><a href="../PC/content-PC-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>">PC</a></li>
            <li><a href="../user/content-user-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>" ><?php echo $l_user?></a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="main">
        <div style="margin-bottom:10px;display: inline-block;min-width:624px;">
			<span style="color: white;"><?php echo $l_carnum?></span>
			<span><input type="text" class="intext" style="width:150px;padding-left: 5px;line-height: 26px;text-align: left;height: 26px;" id="txtcarnumber" name="txtcarnumber"/></span>
			<span style="color: white;padding-left: 20px;"><?php echo $l_from?></span>
			<span><input type="text" class="intext" style="width:100px;padding-left: 5px;line-height: 26px;height: 26px;" id="datepickerfrom" name="datepickerfrom"  /></span>
			<span style="display: inline-block;margin-bottom: 5px;"  id="divUpDown_From">
				<span style="padding-left: 10px;"><input type="text" class="intext" style="width:20px;height:22px" name="txtHour_from" id="txtHour_from" 
						 value="00"/>
				</span><label style="color: white;">:</label>
				<span style="padding-left: 10px;">
					<input type="text" class="intext" style="width:20px;height:22px" name="txtMinutes_from" id="txtMinutes_from" 
						onkeypress="return validateMunite(this,event);" value="00"/>
	            </span><label style="color: white;">:</label>
	            <span style="padding-left: 10px;">
	            	<input type="text" class="intext" style="width:20px;height:22px" name="txtSeconds_from" id="txtSeconds_from" 
	            		onkeypress="return validateMunite(this,event);" value="00"/>
	            </span>
            </span>
			<span style="color: white;padding-left: 20px;"><?php echo $l_to?></span>
			<span><input type="text" class="intext" style="width:100px;padding-left: 5px;line-height: 26px;height: 26px;" id="datepickerto" name="datepickerto"  /></span>
			<span style="display: inline-block;margin-bottom: 5px;"  id="divUpDown_To">
				<span style="padding-left: 10px;"><input type="text" class="intext" style="width:20px;height:22px" name="txtHour_to" id="txtHour_to"
					 value="23"/>
					
				</span><label style="color: white;">:</label>
				<span style="padding-left: 10px;">
					<input type="text" class="intext" style="width:20px;height:22px" name="txtMinutes_from" id="txtMinutes_to" 
						onkeypress="return validateMunite(this,event);" value="59"/>
	            </span><label style="color: white;">:</label>
	            <span style="padding-left: 10px;">
	            	<input type="text" class="intext" style="width:20px;height:22px" name="txtSeconds_from" id="txtSeconds_to" 
	            		onkeypress="return validateMunite(this,event);" value="59"/>
	                	
	            </span>
            </span>
			<span  style="padding-left: 15px;"><input type="button" class="inbtn"  style="width: 65px;" value="<?php echo $l_search?>" onclick="sortAndPagingCarcrime('cc.regDatetime',1)" /></span>
            <span><input type="button" class="inbtn" value="All load"  style="width: 65px;" onclick="searchAll_Carcrime();" /></span>
		</div>
		<div class="divtheader" style="min-width:624px;">
           	<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebodyheader">
	           	<thead>
		            <tr>
		            	<th style="width: 5%">No</th>
		                <th style="width: 15%"><a onclick="sortAndPagingCarcrime('cc.carnum',1)" style="cursor: pointer;color: #027acc"><?php echo $l_carnum?></a></th>
		                <th style="width: 10%"><a onclick="sortAndPagingCarcrime('cc.regDatetime',1)" style="cursor: pointer;color: #027acc"><?php echo $l_time?></a></th>
		                <th style="width: 25%"><a onclick="sortAndPagingCarcrime('cc.regMemo',1)" style="cursor: pointer;color: #027acc"><?php echo $l_regnote?></a></th>
		                <th style="width: 25%"><a onclick="sortAndPagingCarcrime('cc.regNote',1)" style="cursor: pointer;color: #027acc"><?php echo $l_note?></a></th>
		                <th  class="last" style="width: 20%"><a onclick="sortAndPagingCarcrime('cs.szUser',1)" style="cursor: pointer;color: #027acc"><?php echo $l_user?></a></th>
		            </tr>
	            </thead>
           	</table>
        </div>
        <div id="idtablecarcrime" style="width: 100%;">
        <div id="divscroll" style="overflow:scroll;overflow-x: hidden; width:100%; background-color: #ffffff">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebody2">
                        
        </table>
        </div>
         <div>
	       	<table>
	       		<tr>
				    <td class="rf-dt-ftr-carcrime-user" style="text-align: left;padding-top: 15px; " colspan="7">
					<label style="color: white;padding-left: 15px;">  <?php echo $l_totalrecord?></label>
					</td>
						
				</tr>	
	       	</table>
	      </div>
        </div>
    </div>
    <?php include 'show_content_popup_carcrime.php';?>
</body>
</html>
 <?php mysql_close($connection);?>